package connectionSettings;

import java.util.Vector;

import javax.microedition.lcdui.Display;

import connections.ConnectionListener;
import connections.SocketDanoConnection;





public class SocketConnectionSettings extends ConnectionSettings {

	
	public SocketConnectionSettings (ConnectionListener _cl ){
		super("Socket Terminal", _cl);
	}
	
	public SocketConnectionSettings (Display _d){
		super("Socket Terminal",_d);
	}
	
	public void  displayConnectionInterface(){

		if (getCurrentAddress() == null ){
			setCurrentAddress("111.111.111.111 9999");
		}
		
		super.displayConnectionInterface();
		Vector methods = new Vector();
		methods.addElement("Direct");
		methods.addElement("Wait For Connection");
		presentActionChoices("How do you want to connect", methods);
		address.setLabel("IP Port separated by a space");
	}

	public void initConnection(String _ip, int _port){

		myConnection = new SocketDanoConnection(_ip, _port,cl);// "000B53130594"
		addListener(cl);
	}
	
	public void madeChoice(int _which, String _choice) {
		if (_choice.equals("Wait For Connection")) {
			
		} else if (_choice.equals("Direct")) {
			String[] params = getAddressParams();
			String ip = params[0];
			int port = 9001;
			if (params.length > 1) port = Integer.parseInt(params[1]);
			
			initConnection(ip,port);
		} 
	}



}
